<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户显示经费列表</title>
    
    <link rel="stylesheet" type="text/css" href="easyui/1.3.4/themes/default/easyui.css" />
    <script type="text/javascript" src="js/axios.js"></script>
    <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="easyui/1.3.4/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/1.3.4/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
<div class="search-box" style="margin: 10px 0">
    <input id="keyword" type="text" placeholder="请输入项目id">
    <button onclick="fetchData()">查询</button>
</div>
<table class="easyui-datagrid" id="empTable" title="" data-options="singleSelect:true,collapsible:true">
    <thead>
    <tr>
        <th data-options="field:'approvalId'">经费申请id</th>
        <th data-options="field:'projectId'">经费申请项目id</th>
        <th data-options="field:'amount',width: '600'">申请数额</th>
        <th data-options="field:'approvalDate'">申请时间</th>
        <th data-options="field:'approvalStatus'">申请状态</th>
        <th data-options="field:'approvalSponsor'">发起人</th>
        <th data-options="field:'actions',width: '300',formatter:formatAction">操作</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </tbody>
</table>
<script>
    function formatAction(val,row){
        return `
                <div class="link-list" style="display: flex; align-items: center">
                    <span d_id="${row.departmentId}" style="margin: 0 5px; color: #1146a6; cursor: pointer" onclick="window.location.href='./updateFundingApproval.html?id=' + ${row.approvalId}">修改</span>
                    <div class="divider" style="height: 10px;border: 1px solid #ccc;"></div>
                    <span d_id="${row.approvalId}" onclick="deleteCurrent(${row.approvalId})" style="margin: 0 5px; color: #1146a6; cursor: pointer">删除</span>
                    

                </div>
            `
    }
    const user = JSON.parse(localStorage.getItem("userinfo"));
    const deleteCurrent = (id) => {
        axios.get("http://localhost:8080/fundingApproval/detail?id=" + id).then(({data}) => {
            if(data.data.projectSponsor==user.teacherName||user.teacherTitle!="用户"){
            axios.post("http://localhost:8080/fundingApproval/delete?id=" + id).then(({data}) => {
            window.location.reload();
        })
            }
       else{
        alert("无权删除信息");
        top.location.reload(true);
       }
    })
}
    
    const fetchData = () => {
        const keyword = $('#keyword').val()
        axios.get(`http://localhost:8080/fundingApproval/list?keyword=${keyword}`).then(({data}) => {
            $('#empTable').datagrid({
                data: data.data
            })
        })
    }
    
    window.onload = () => {
        axios.get('http://localhost:8080/fundingApproval/list').then(({data}) => {
            $('#empTable').datagrid({
                data: data.data
            })
        })
        
        
    }
</script>

</body>
</html>